package study.elasticsearch.controller;

import factory.SourceInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.ReceiveVo;
import study.elasticsearch.repository.BbsSearchRepository;

@RestController
public class BbsSearchController {

    private final BbsSearchRepository searchRepository;

    public BbsSearchController(BbsSearchRepository bbsSearchRepository) {
        this.searchRepository = bbsSearchRepository;
    }

    /**
     * 搜索
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/search")
    public String search(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return searchRepository.search(info);
    }

    /**
     * 分页搜索
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/limitSearch")
    public String limitSearch(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return searchRepository.limitSearch(info);
    }

    /**
     * 排序搜索
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/sortSearch")
    public String sortSearch(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return searchRepository.sortSearch(info);
    }

    /**
     * 搜索高亮显示
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/highLightSearch")
    public String highLightSearch(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return searchRepository.highLightSearch(info);
    }

    /**
     * 聚合
     * @param vo ReceiveVo
     * @return
     */
    @RequestMapping("/aggSearch")
    public String aggSearch(ReceiveVo vo) {
        SourceInfo info = SourceInfo.builder().setIndex(vo.getIndex()).setId(vo.getId()).setType(vo.getType())
                .build();
        return searchRepository.aggSearch(info);
    }
}
